package com.ecoolex.chinadutyfree.retailer.job.consumer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.ecoolex.framework.message.queue.Consumer;
import com.ecoolex.framework.message.queue.ConsumerComponent;
import com.ecoolex.framework.message.queue.Message;
import com.ecoolex.framework.message.queue.ProducerManager;

import com.ecoolex.chinadutyfree.retailer.Constant;


// @ConsumerComponent
public class SampleConsumer {

	private Logger log = LoggerFactory.getLogger(SampleConsumer.class);


	// 系统-模块-功能-动作
	@Consumer(group= Constant.MODULE_NAME, theme = "系统-模块-功能-动作", describe = "消费描述")
	public void consumer(Message message) throws Exception {
		log.info("消费开始[{}]={}", message.getTheme(), message.getMessageId());
		try {
			// code
		} catch (Exception e) {
			log.error("消费异常[{}]={}", message.getTheme(), message.getMessageId(), e);
			throw e;
		} finally {
			log.info("消费结束[{}]={}", message.getTheme(), message.getMessageId());
		}
	}


	// 生产者示例
	@Autowired
	private ProducerManager producerManager;


	public void sendSampleMessage(String content) {
		producerManager.sendAsync(new Message("系统-模块-功能-动作", content));
	}
}
